<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActionView::Helpers::DateHelper</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            ActionView::Helpers::DateHelper 
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/actionpack/lib/action_view/helpers/date_helper_rb.html">actionpack/lib/action_view/helpers/date_helper.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<h1 id="label-Action+View+Date+Helpers">Action View <a href="../../Date.html">Date</a> <a href="../Helpers.html">Helpers</a></h1>

<p>The <a href="../../Date.html">Date</a> Helper primarily creates
select/option tags for different kinds of dates and times or date and time
elements. All of the select-type methods share a number of common options
that are as follows:</p>
<ul><li>
<p><code>:prefix</code> - overwrites the default prefix of "date" used for the
select names. So specifying "birthday" would give birthday[month] instead
of date[month] if passed to the <code>select_month</code> method.</p>
</li><li>
<p><code>:include_blank</code> - set to true if it should be possible to set
an empty date.</p>
</li><li>
<p><code>:discard_type</code> - set to true if you want to discard the type
part of the select name. If set to true, the <code>select_month</code>
method would use simply "date" (which can be overwritten using
<code>:prefix</code>) instead of date[month].</p>
</li></ul>

    </div>
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>D</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="DateHelper.html#method-i-date_select">date_select</a>,
              </li>
            
              
              <li>
                <a href="DateHelper.html#method-i-datetime_select">datetime_select</a>,
              </li>
            
              
              <li>
                <a href="DateHelper.html#method-i-distance_of_time_in_words">distance_of_time_in_words</a>,
              </li>
            
              
              <li>
                <a href="DateHelper.html#method-i-distance_of_time_in_words_to_now">distance_of_time_in_words_to_now</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>S</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="DateHelper.html#method-i-select_date">select_date</a>,
              </li>
            
              
              <li>
                <a href="DateHelper.html#method-i-select_datetime">select_datetime</a>,
              </li>
            
              
              <li>
                <a href="DateHelper.html#method-i-select_day">select_day</a>,
              </li>
            
              
              <li>
                <a href="DateHelper.html#method-i-select_hour">select_hour</a>,
              </li>
            
              
              <li>
                <a href="DateHelper.html#method-i-select_minute">select_minute</a>,
              </li>
            
              
              <li>
                <a href="DateHelper.html#method-i-select_month">select_month</a>,
              </li>
            
              
              <li>
                <a href="DateHelper.html#method-i-select_second">select_second</a>,
              </li>
            
              
              <li>
                <a href="DateHelper.html#method-i-select_time">select_time</a>,
              </li>
            
              
              <li>
                <a href="DateHelper.html#method-i-select_year">select_year</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>T</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="DateHelper.html#method-i-time_ago_in_words">time_ago_in_words</a>,
              </li>
            
              
              <li>
                <a href="DateHelper.html#method-i-time_select">time_select</a>,
              </li>
            
              
              <li>
                <a href="DateHelper.html#method-i-time_tag">time_tag</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-date_select">
            
              <b>date_select</b>(object_name, method, options = {}, html_options = {})
            
            <a href="DateHelper.html#method-i-date_select" name="method-i-date_select" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a set of select tags (one for year, month, and day) pre-selected
for accessing a specified date-based attribute (identified by
<code>method</code>) on an object assigned to the template (identified by
<code>object</code>).</p>

<h4 id="method-i-date_select-label-Options">Options</h4>
<ul><li>
<p><code>:use_month_numbers</code> - Set to true if you want to use month
numbers rather than month names (e.g. "2" instead of "February").</p>
</li><li>
<p><code>:use_two_digit_numbers</code> - Set to true if you want to display
two digit month and day numbers (e.g. "02" instead of "February" and "08"
instead of "8").</p>
</li><li>
<p><code>:use_short_month</code>   - Set to true if you want to use
abbreviated month names instead of full month names (e.g. "Feb" instead of
"February").</p>
</li><li>
<p><code>:add_month_numbers</code>  - Set to true if you want to use both
month numbers and month names (e.g. "2 - February" instead of "February").</p>
</li><li>
<p><code>:use_month_names</code>   - Set to an array with 12 month names if
you want to customize month names. Note: You can also use Rails' i18n
functionality for this.</p>
</li><li>
<p><code>:date_separator</code>    - Specifies a string to separate the date
fields. Default is "" (i.e. nothing).</p>
</li><li>
<p><code>:start_year</code>        - Set the start year for the year select.
Default is <code>Time.now.year - 5</code>.</p>
</li><li>
<p><code>:end_year</code>          - Set the end year for the year select.
Default is <code>Time.now.year + 5</code>.</p>
</li><li>
<p><code>:discard_day</code>       - Set to true if you don't want to show a
day select. This includes the day as a hidden field instead of showing a
select field. Also note that this implicitly sets the day to be the first
of the given month in order to not create invalid dates like 31 February.</p>
</li><li>
<p><code>:discard_month</code>     - Set to true if you don't want to show a
month select. This includes the month as a hidden field instead of showing
a select field. Also note that this implicitly sets :discard_day to true.</p>
</li><li>
<p><code>:discard_year</code>      - Set to true if you don't want to show a
year select. This includes the year as a hidden field instead of showing a
select field.</p>
</li><li>
<p><code>:order</code>             - Set to an array containing
<code>:day</code>, <code>:month</code> and <code>:year</code> to customize
the order in which the select fields are shown. If you leave out any of the
symbols, the respective select will not be shown (like when you set
<code>discard_xxx: true</code>. Defaults to the order defined in the
respective locale (e.g. [:year, :month, :day] in the en locale that ships
with <a href="../../Rails.html">Rails</a>).</p>
</li><li>
<p><code>:include_blank</code>     - Include a blank option in every select
field so it's possible to set empty dates.</p>
</li><li>
<p><code>:default</code>           - Set a default date if the affected date
isn't set or is nil.</p>
</li><li>
<p><code>:selected</code>          - Set a date that overrides the actual
value.</p>
</li><li>
<p><code>:disabled</code>          - Set to true if you want show the select
fields as disabled.</p>
</li><li>
<p><code>:prompt</code>            - Set to true (for a generic prompt), a
prompt string or a hash of prompt strings for <code>:year</code>,
<code>:month</code>, <code>:day</code>, <code>:hour</code>,
<code>:minute</code> and <code>:second</code>. Setting this option prepends
a select option with a generic prompt  (Day, Month, Year, Hour, Minute,
Seconds) or the given prompt string.</p>
</li><li>
<p><code>:with_css_classes</code>   - Set to true if you want assign different
styles for 'select' tags. This option automatically set classes 'year',
'month', 'day', 'hour', 'minute' and 'second' for your 'select' tags.</p>
</li></ul>

<p>If anything is passed in the <code>html_options</code> hash it will be
applied to every select tag in the set.</p>

<p>NOTE: Discarded selects will default to 1. So if no month select is
available, January will be assumed.</p>

<pre># Generates a date select that when POSTed is stored in the article variable, in the written_on attribute.
date_select(&quot;article&quot;, &quot;written_on&quot;)

# Generates a date select that when POSTed is stored in the article variable, in the written_on attribute,
# with the year in the year drop down box starting at 1995.
date_select(&quot;article&quot;, &quot;written_on&quot;, start_year: 1995)

# Generates a date select that when POSTed is stored in the article variable, in the written_on attribute,
# with the year in the year drop down box starting at 1995, numbers used for months instead of words,
# and without a day select box.
date_select(&quot;article&quot;, &quot;written_on&quot;, start_year: 1995, use_month_numbers: true,
                                  discard_day: true, include_blank: true)

# Generates a date select that when POSTed is stored in the article variable, in the written_on attribute,
# with two digit numbers used for months and days.
date_select(&quot;article&quot;, &quot;written_on&quot;, use_two_digit_numbers: true)

# Generates a date select that when POSTed is stored in the article variable, in the written_on attribute
# with the fields ordered as day, month, year rather than month, day, year.
date_select(&quot;article&quot;, &quot;written_on&quot;, order: [:day, :month, :year])

# Generates a date select that when POSTed is stored in the user variable, in the birthday attribute
# lacking a year field.
date_select(&quot;user&quot;, &quot;birthday&quot;, order: [:month, :day])

# Generates a date select that when POSTed is stored in the article variable, in the written_on attribute
# which is initially set to the date 3 days from the current date
date_select(&quot;article&quot;, &quot;written_on&quot;, default: 3.days.from_now)

# Generates a date select that when POSTed is stored in the article variable, in the written_on attribute
# which is set in the form with todays date, regardless of the value in the Active Record object.
date_select(&quot;article&quot;, &quot;written_on&quot;, selected: Date.today)

# Generates a date select that when POSTed is stored in the credit_card variable, in the bill_due attribute
# that will have a default day of 20.
date_select(&quot;credit_card&quot;, &quot;bill_due&quot;, default: { day: 20 })

# Generates a date select with custom prompts.
date_select(&quot;article&quot;, &quot;written_on&quot;, prompt: { day: 'Select day', month: 'Select month', year: 'Select year' })</pre>

<p>The selects are prepared for multi-parameter assignment to an Active Record
object.</p>

<p>Note: If the day is not included as an option but the month is, the day
will be set to the 1st to ensure that all month choices are valid.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-date_select_source')" id="l_method-i-date_select_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c52c2682bf03192755ccf8c15ab641090815cacf/actionpack/lib/action_view/helpers/date_helper.rb#L254" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-date_select_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/date_helper.rb, line 254</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">date_select</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">DateSelect</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">html_options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-datetime_select">
            
              <b>datetime_select</b>(object_name, method, options = {}, html_options = {})
            
            <a href="DateHelper.html#method-i-datetime_select" name="method-i-datetime_select" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a set of select tags (one for year, month, day, hour, and minute)
pre-selected for accessing a specified datetime-based attribute (identified
by <code>method</code>) on an object assigned to the template (identified
by <code>object</code>).</p>

<p>If anything is passed in the html_options hash it will be applied to every
select tag in the set.</p>

<pre># Generates a datetime select that, when POSTed, will be stored in the article variable in the written_on
# attribute.
datetime_select(&quot;article&quot;, &quot;written_on&quot;)

# Generates a datetime select with a year select that starts at 1995 that, when POSTed, will be stored in the
# article variable in the written_on attribute.
datetime_select(&quot;article&quot;, &quot;written_on&quot;, start_year: 1995)

# Generates a datetime select with a default value of 3 days from the current time that, when POSTed, will
# be stored in the trip variable in the departing attribute.
datetime_select(&quot;trip&quot;, &quot;departing&quot;, default: 3.days.from_now)

# Generate a datetime select with hours in the AM/PM format
datetime_select(&quot;article&quot;, &quot;written_on&quot;, ampm: true)

# Generates a datetime select that discards the type that, when POSTed, will be stored in the article variable
# as the written_on attribute.
datetime_select(&quot;article&quot;, &quot;written_on&quot;, discard_type: true)

# Generates a datetime select with a custom prompt. Use &lt;tt&gt;prompt: true&lt;/tt&gt; for generic prompts.
datetime_select(&quot;article&quot;, &quot;written_on&quot;, prompt: {day: 'Choose day', month: 'Choose month', year: 'Choose year'})
datetime_select(&quot;article&quot;, &quot;written_on&quot;, prompt: {hour: true}) # generic prompt for hours
datetime_select(&quot;article&quot;, &quot;written_on&quot;, prompt: true) # generic prompts for all</pre>

<p>The selects are prepared for multi-parameter assignment to an Active Record
object.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-datetime_select_source')" id="l_method-i-datetime_select_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c52c2682bf03192755ccf8c15ab641090815cacf/actionpack/lib/action_view/helpers/date_helper.rb#L326" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-datetime_select_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/date_helper.rb, line 326</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">datetime_select</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">DatetimeSelect</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">html_options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-distance_of_time_in_words">
            
              <b>distance_of_time_in_words</b>(from_time, to_time = 0, include_seconds_or_options = {}, options = {})
            
            <a href="DateHelper.html#method-i-distance_of_time_in_words" name="method-i-distance_of_time_in_words" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Reports the approximate distance in time between two <a
href="../../Time.html">Time</a>, <a href="../../Date.html">Date</a> or <a
href="../../DateTime.html">DateTime</a> objects or integers as seconds.
Pass <code>include_seconds: true</code> if you want more detailed
approximations when distance &lt; 1 min, 29 secs. Distances are reported
based on the following table:</p>

<pre class="ruby"><span class="ruby-value">0</span> <span class="ruby-operator">&lt;</span><span class="ruby-operator">-</span><span class="ruby-operator">&gt;</span> <span class="ruby-value">29</span> <span class="ruby-identifier">secs</span>                                                             <span class="ruby-comment"># =&gt; less than a minute</span>
<span class="ruby-value">30</span> <span class="ruby-identifier">secs</span> <span class="ruby-operator">&lt;</span><span class="ruby-operator">-</span><span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span> <span class="ruby-identifier">min</span>, <span class="ruby-value">29</span> <span class="ruby-identifier">secs</span>                                                <span class="ruby-comment"># =&gt; 1 minute</span>
<span class="ruby-value">1</span> <span class="ruby-identifier">min</span>, <span class="ruby-value">30</span> <span class="ruby-identifier">secs</span> <span class="ruby-operator">&lt;</span><span class="ruby-operator">-</span><span class="ruby-operator">&gt;</span> <span class="ruby-value">44</span> <span class="ruby-identifier">mins</span>, <span class="ruby-value">29</span> <span class="ruby-identifier">secs</span>                                       <span class="ruby-comment"># =&gt; [2..44] minutes</span>
<span class="ruby-value">44</span> <span class="ruby-identifier">mins</span>, <span class="ruby-value">30</span> <span class="ruby-identifier">secs</span> <span class="ruby-operator">&lt;</span><span class="ruby-operator">-</span><span class="ruby-operator">&gt;</span> <span class="ruby-value">89</span> <span class="ruby-identifier">mins</span>, <span class="ruby-value">29</span> <span class="ruby-identifier">secs</span>                                     <span class="ruby-comment"># =&gt; about 1 hour</span>
<span class="ruby-value">89</span> <span class="ruby-identifier">mins</span>, <span class="ruby-value">30</span> <span class="ruby-identifier">secs</span> <span class="ruby-operator">&lt;</span><span class="ruby-operator">-</span><span class="ruby-operator">&gt;</span> <span class="ruby-value">23</span> <span class="ruby-identifier">hrs</span>, <span class="ruby-value">59</span> <span class="ruby-identifier">mins</span>, <span class="ruby-value">29</span> <span class="ruby-identifier">secs</span>                             <span class="ruby-comment"># =&gt; about [2..24] hours</span>
<span class="ruby-value">23</span> <span class="ruby-identifier">hrs</span>, <span class="ruby-value">59</span> <span class="ruby-identifier">mins</span>, <span class="ruby-value">30</span> <span class="ruby-identifier">secs</span> <span class="ruby-operator">&lt;</span><span class="ruby-operator">-</span><span class="ruby-operator">&gt;</span> <span class="ruby-value">41</span> <span class="ruby-identifier">hrs</span>, <span class="ruby-value">59</span> <span class="ruby-identifier">mins</span>, <span class="ruby-value">29</span> <span class="ruby-identifier">secs</span>                     <span class="ruby-comment"># =&gt; 1 day</span>
<span class="ruby-value">41</span> <span class="ruby-identifier">hrs</span>, <span class="ruby-value">59</span> <span class="ruby-identifier">mins</span>, <span class="ruby-value">30</span> <span class="ruby-identifier">secs</span>  <span class="ruby-operator">&lt;</span><span class="ruby-operator">-</span><span class="ruby-operator">&gt;</span> <span class="ruby-value">29</span> <span class="ruby-identifier">days</span>, <span class="ruby-value">23</span> <span class="ruby-identifier">hrs</span>, <span class="ruby-value">59</span> <span class="ruby-identifier">mins</span>, <span class="ruby-value">29</span> <span class="ruby-identifier">secs</span>           <span class="ruby-comment"># =&gt; [2..29] days</span>
<span class="ruby-value">29</span> <span class="ruby-identifier">days</span>, <span class="ruby-value">23</span> <span class="ruby-identifier">hrs</span>, <span class="ruby-value">59</span> <span class="ruby-identifier">mins</span>, <span class="ruby-value">30</span> <span class="ruby-identifier">secs</span> <span class="ruby-operator">&lt;</span><span class="ruby-operator">-</span><span class="ruby-operator">&gt;</span> <span class="ruby-value">44</span> <span class="ruby-identifier">days</span>, <span class="ruby-value">23</span> <span class="ruby-identifier">hrs</span>, <span class="ruby-value">59</span> <span class="ruby-identifier">mins</span>, <span class="ruby-value">29</span> <span class="ruby-identifier">secs</span>   <span class="ruby-comment"># =&gt; about 1 month</span>
<span class="ruby-value">44</span> <span class="ruby-identifier">days</span>, <span class="ruby-value">23</span> <span class="ruby-identifier">hrs</span>, <span class="ruby-value">59</span> <span class="ruby-identifier">mins</span>, <span class="ruby-value">30</span> <span class="ruby-identifier">secs</span> <span class="ruby-operator">&lt;</span><span class="ruby-operator">-</span><span class="ruby-operator">&gt;</span> <span class="ruby-value">59</span> <span class="ruby-identifier">days</span>, <span class="ruby-value">23</span> <span class="ruby-identifier">hrs</span>, <span class="ruby-value">59</span> <span class="ruby-identifier">mins</span>, <span class="ruby-value">29</span> <span class="ruby-identifier">secs</span>   <span class="ruby-comment"># =&gt; about 2 months</span>
<span class="ruby-value">59</span> <span class="ruby-identifier">days</span>, <span class="ruby-value">23</span> <span class="ruby-identifier">hrs</span>, <span class="ruby-value">59</span> <span class="ruby-identifier">mins</span>, <span class="ruby-value">30</span> <span class="ruby-identifier">secs</span> <span class="ruby-operator">&lt;</span><span class="ruby-operator">-</span><span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span> <span class="ruby-identifier">yr</span> <span class="ruby-identifier">minus</span> <span class="ruby-value">1</span> <span class="ruby-identifier">sec</span>                    <span class="ruby-comment"># =&gt; [2..12] months</span>
<span class="ruby-value">1</span> <span class="ruby-identifier">yr</span> <span class="ruby-operator">&lt;</span><span class="ruby-operator">-</span><span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span> <span class="ruby-identifier">yr</span>, <span class="ruby-value">3</span> <span class="ruby-identifier">months</span>                                                   <span class="ruby-comment"># =&gt; about 1 year</span>
<span class="ruby-value">1</span> <span class="ruby-identifier">yr</span>, <span class="ruby-value">3</span> <span class="ruby-identifier">months</span> <span class="ruby-operator">&lt;</span><span class="ruby-operator">-</span><span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span> <span class="ruby-identifier">yr</span>, <span class="ruby-value">9</span> <span class="ruby-identifier">months</span>                                         <span class="ruby-comment"># =&gt; over 1 year</span>
<span class="ruby-value">1</span> <span class="ruby-identifier">yr</span>, <span class="ruby-value">9</span> <span class="ruby-identifier">months</span> <span class="ruby-operator">&lt;</span><span class="ruby-operator">-</span><span class="ruby-operator">&gt;</span> <span class="ruby-value">2</span> <span class="ruby-identifier">yr</span> <span class="ruby-identifier">minus</span> <span class="ruby-value">1</span> <span class="ruby-identifier">sec</span>                                       <span class="ruby-comment"># =&gt; almost 2 years</span>
<span class="ruby-value">2</span> <span class="ruby-identifier">yrs</span> <span class="ruby-operator">&lt;</span><span class="ruby-operator">-</span><span class="ruby-operator">&gt;</span> <span class="ruby-identifier">max</span> <span class="ruby-identifier">time</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">date</span>                                                <span class="ruby-comment"># =&gt; (same rules as 1 yr)</span>
</pre>

<p>With <code>include_seconds: true</code> and the difference &lt; 1 minute 29
seconds:</p>

<pre class="ruby"><span class="ruby-value">0</span><span class="ruby-operator">-</span><span class="ruby-value">4</span>   <span class="ruby-identifier">secs</span>      <span class="ruby-comment"># =&gt; less than 5 seconds</span>
<span class="ruby-value">5</span><span class="ruby-operator">-</span><span class="ruby-value">9</span>   <span class="ruby-identifier">secs</span>      <span class="ruby-comment"># =&gt; less than 10 seconds</span>
<span class="ruby-value">10</span><span class="ruby-operator">-</span><span class="ruby-value">19</span> <span class="ruby-identifier">secs</span>      <span class="ruby-comment"># =&gt; less than 20 seconds</span>
<span class="ruby-value">20</span><span class="ruby-operator">-</span><span class="ruby-value">39</span> <span class="ruby-identifier">secs</span>      <span class="ruby-comment"># =&gt; half a minute</span>
<span class="ruby-value">40</span><span class="ruby-operator">-</span><span class="ruby-value">59</span> <span class="ruby-identifier">secs</span>      <span class="ruby-comment"># =&gt; less than a minute</span>
<span class="ruby-value">60</span><span class="ruby-operator">-</span><span class="ruby-value">89</span> <span class="ruby-identifier">secs</span>      <span class="ruby-comment"># =&gt; 1 minute</span>

<span class="ruby-identifier">from_time</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
<span class="ruby-identifier">distance_of_time_in_words</span>(<span class="ruby-identifier">from_time</span>, <span class="ruby-identifier">from_time</span> <span class="ruby-operator">+</span> <span class="ruby-value">50</span>.<span class="ruby-identifier">minutes</span>)                                <span class="ruby-comment"># =&gt; about 1 hour</span>
<span class="ruby-identifier">distance_of_time_in_words</span>(<span class="ruby-identifier">from_time</span>, <span class="ruby-value">50</span>.<span class="ruby-identifier">minutes</span>.<span class="ruby-identifier">from_now</span>)                                   <span class="ruby-comment"># =&gt; about 1 hour</span>
<span class="ruby-identifier">distance_of_time_in_words</span>(<span class="ruby-identifier">from_time</span>, <span class="ruby-identifier">from_time</span> <span class="ruby-operator">+</span> <span class="ruby-value">15</span>.<span class="ruby-identifier">seconds</span>)                                <span class="ruby-comment"># =&gt; less than a minute</span>
<span class="ruby-identifier">distance_of_time_in_words</span>(<span class="ruby-identifier">from_time</span>, <span class="ruby-identifier">from_time</span> <span class="ruby-operator">+</span> <span class="ruby-value">15</span>.<span class="ruby-identifier">seconds</span>, <span class="ruby-identifier">include_seconds</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>)      <span class="ruby-comment"># =&gt; less than 20 seconds</span>
<span class="ruby-identifier">distance_of_time_in_words</span>(<span class="ruby-identifier">from_time</span>, <span class="ruby-value">3</span>.<span class="ruby-identifier">years</span>.<span class="ruby-identifier">from_now</span>)                                      <span class="ruby-comment"># =&gt; about 3 years</span>
<span class="ruby-identifier">distance_of_time_in_words</span>(<span class="ruby-identifier">from_time</span>, <span class="ruby-identifier">from_time</span> <span class="ruby-operator">+</span> <span class="ruby-value">60</span>.<span class="ruby-identifier">hours</span>)                                  <span class="ruby-comment"># =&gt; 3 days</span>
<span class="ruby-identifier">distance_of_time_in_words</span>(<span class="ruby-identifier">from_time</span>, <span class="ruby-identifier">from_time</span> <span class="ruby-operator">+</span> <span class="ruby-value">45</span>.<span class="ruby-identifier">seconds</span>, <span class="ruby-identifier">include_seconds</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>)      <span class="ruby-comment"># =&gt; less than a minute</span>
<span class="ruby-identifier">distance_of_time_in_words</span>(<span class="ruby-identifier">from_time</span>, <span class="ruby-identifier">from_time</span> <span class="ruby-operator">-</span> <span class="ruby-value">45</span>.<span class="ruby-identifier">seconds</span>, <span class="ruby-identifier">include_seconds</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>)      <span class="ruby-comment"># =&gt; less than a minute</span>
<span class="ruby-identifier">distance_of_time_in_words</span>(<span class="ruby-identifier">from_time</span>, <span class="ruby-value">76</span>.<span class="ruby-identifier">seconds</span>.<span class="ruby-identifier">from_now</span>)                                   <span class="ruby-comment"># =&gt; 1 minute</span>
<span class="ruby-identifier">distance_of_time_in_words</span>(<span class="ruby-identifier">from_time</span>, <span class="ruby-identifier">from_time</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">year</span> <span class="ruby-operator">+</span> <span class="ruby-value">3</span>.<span class="ruby-identifier">days</span>)                           <span class="ruby-comment"># =&gt; about 1 year</span>
<span class="ruby-identifier">distance_of_time_in_words</span>(<span class="ruby-identifier">from_time</span>, <span class="ruby-identifier">from_time</span> <span class="ruby-operator">+</span> <span class="ruby-value">3</span>.<span class="ruby-identifier">years</span> <span class="ruby-operator">+</span> <span class="ruby-value">6</span>.<span class="ruby-identifier">months</span>)                        <span class="ruby-comment"># =&gt; over 3 years</span>
<span class="ruby-identifier">distance_of_time_in_words</span>(<span class="ruby-identifier">from_time</span>, <span class="ruby-identifier">from_time</span> <span class="ruby-operator">+</span> <span class="ruby-value">4</span>.<span class="ruby-identifier">years</span> <span class="ruby-operator">+</span> <span class="ruby-value">9</span>.<span class="ruby-identifier">days</span> <span class="ruby-operator">+</span> <span class="ruby-value">30</span>.<span class="ruby-identifier">minutes</span> <span class="ruby-operator">+</span> <span class="ruby-value">5</span>.<span class="ruby-identifier">seconds</span>) <span class="ruby-comment"># =&gt; about 4 years</span>

<span class="ruby-identifier">to_time</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span> <span class="ruby-operator">+</span> <span class="ruby-value">6</span>.<span class="ruby-identifier">years</span> <span class="ruby-operator">+</span> <span class="ruby-value">19</span>.<span class="ruby-identifier">days</span>
<span class="ruby-identifier">distance_of_time_in_words</span>(<span class="ruby-identifier">from_time</span>, <span class="ruby-identifier">to_time</span>, <span class="ruby-identifier">include_seconds</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>)                     <span class="ruby-comment"># =&gt; about 6 years</span>
<span class="ruby-identifier">distance_of_time_in_words</span>(<span class="ruby-identifier">to_time</span>, <span class="ruby-identifier">from_time</span>, <span class="ruby-identifier">include_seconds</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>)                     <span class="ruby-comment"># =&gt; about 6 years</span>
<span class="ruby-identifier">distance_of_time_in_words</span>(<span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>, <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>)                                               <span class="ruby-comment"># =&gt; less than a minute</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-distance_of_time_in_words_source')" id="l_method-i-distance_of_time_in_words_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c52c2682bf03192755ccf8c15ab641090815cacf/actionpack/lib/action_view/helpers/date_helper.rb#L67" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-distance_of_time_in_words_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/date_helper.rb, line 67</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">distance_of_time_in_words</span>(<span class="ruby-identifier">from_time</span>, <span class="ruby-identifier">to_time</span> = <span class="ruby-number">0</span>, <span class="ruby-identifier">include_seconds_or_options</span> = {}, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">include_seconds_or_options</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
    <span class="ruby-identifier">options</span> = <span class="ruby-identifier">include_seconds_or_options</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Deprecation</span>.<span class="ruby-identifier">warn</span> <span class="ruby-string">&quot;distance_of_time_in_words and time_ago_in_words now accept :include_seconds &quot;</span> <span class="ruby-operator">+</span>
                                    <span class="ruby-string">&quot;as a part of options hash, not a boolean argument&quot;</span>
    <span class="ruby-identifier">options</span>[<span class="ruby-value">:include_seconds</span>] <span class="ruby-operator">||=</span> <span class="ruby-operator">!</span><span class="ruby-operator">!</span><span class="ruby-identifier">include_seconds_or_options</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">options</span> = {
    <span class="ruby-identifier">scope</span><span class="ruby-operator">:</span> <span class="ruby-value">:'datetime.distance_in_words'</span>
  }.<span class="ruby-identifier">merge!</span>(<span class="ruby-identifier">options</span>)

  <span class="ruby-identifier">from_time</span> = <span class="ruby-identifier">from_time</span>.<span class="ruby-identifier">to_time</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">from_time</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:to_time</span>)
  <span class="ruby-identifier">to_time</span> = <span class="ruby-identifier">to_time</span>.<span class="ruby-identifier">to_time</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">to_time</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:to_time</span>)
  <span class="ruby-identifier">from_time</span>, <span class="ruby-identifier">to_time</span> = <span class="ruby-identifier">to_time</span>, <span class="ruby-identifier">from_time</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">from_time</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">to_time</span>
  <span class="ruby-identifier">distance_in_minutes</span> = ((<span class="ruby-identifier">to_time</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">from_time</span>)<span class="ruby-operator">/</span><span class="ruby-number">60.0</span>).<span class="ruby-identifier">round</span>
  <span class="ruby-identifier">distance_in_seconds</span> = (<span class="ruby-identifier">to_time</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">from_time</span>).<span class="ruby-identifier">round</span>

  <span class="ruby-constant">I18n</span>.<span class="ruby-identifier">with_options</span> <span class="ruby-value">:locale</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:locale</span>], <span class="ruby-value">:scope</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:scope</span>] <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">locale</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">case</span> <span class="ruby-identifier">distance_in_minutes</span>
      <span class="ruby-keyword">when</span> <span class="ruby-number">0</span><span class="ruby-operator">..</span><span class="ruby-number">1</span>
        <span class="ruby-keyword">return</span> <span class="ruby-identifier">distance_in_minutes</span> <span class="ruby-operator">==</span> <span class="ruby-number">0</span> <span class="ruby-operator">?</span>
               <span class="ruby-identifier">locale</span>.<span class="ruby-identifier">t</span>(<span class="ruby-value">:less_than_x_minutes</span>, <span class="ruby-value">:count</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-number">1</span>) <span class="ruby-operator">:</span>
               <span class="ruby-identifier">locale</span>.<span class="ruby-identifier">t</span>(<span class="ruby-value">:x_minutes</span>, <span class="ruby-value">:count</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">distance_in_minutes</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:include_seconds</span>]

        <span class="ruby-keyword">case</span> <span class="ruby-identifier">distance_in_seconds</span>
          <span class="ruby-keyword">when</span> <span class="ruby-number">0</span><span class="ruby-operator">..</span><span class="ruby-number">4</span>   <span class="ruby-keyword">then</span> <span class="ruby-identifier">locale</span>.<span class="ruby-identifier">t</span> <span class="ruby-value">:less_than_x_seconds</span>, <span class="ruby-value">:count</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-number">5</span>
          <span class="ruby-keyword">when</span> <span class="ruby-number">5</span><span class="ruby-operator">..</span><span class="ruby-number">9</span>   <span class="ruby-keyword">then</span> <span class="ruby-identifier">locale</span>.<span class="ruby-identifier">t</span> <span class="ruby-value">:less_than_x_seconds</span>, <span class="ruby-value">:count</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-number">10</span>
          <span class="ruby-keyword">when</span> <span class="ruby-number">10</span><span class="ruby-operator">..</span><span class="ruby-number">19</span> <span class="ruby-keyword">then</span> <span class="ruby-identifier">locale</span>.<span class="ruby-identifier">t</span> <span class="ruby-value">:less_than_x_seconds</span>, <span class="ruby-value">:count</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-number">20</span>
          <span class="ruby-keyword">when</span> <span class="ruby-number">20</span><span class="ruby-operator">..</span><span class="ruby-number">39</span> <span class="ruby-keyword">then</span> <span class="ruby-identifier">locale</span>.<span class="ruby-identifier">t</span> <span class="ruby-value">:half_a_minute</span>
          <span class="ruby-keyword">when</span> <span class="ruby-number">40</span><span class="ruby-operator">..</span><span class="ruby-number">59</span> <span class="ruby-keyword">then</span> <span class="ruby-identifier">locale</span>.<span class="ruby-identifier">t</span> <span class="ruby-value">:less_than_x_minutes</span>, <span class="ruby-value">:count</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-number">1</span>
          <span class="ruby-keyword">else</span>             <span class="ruby-identifier">locale</span>.<span class="ruby-identifier">t</span> <span class="ruby-value">:x_minutes</span>,           <span class="ruby-value">:count</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-number">1</span>
        <span class="ruby-keyword">end</span>

      <span class="ruby-keyword">when</span> <span class="ruby-number">2</span><span class="ruby-operator">...</span><span class="ruby-number">45</span>           <span class="ruby-keyword">then</span> <span class="ruby-identifier">locale</span>.<span class="ruby-identifier">t</span> <span class="ruby-value">:x_minutes</span>,      <span class="ruby-value">:count</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">distance_in_minutes</span>
      <span class="ruby-keyword">when</span> <span class="ruby-number">45</span><span class="ruby-operator">...</span><span class="ruby-number">90</span>          <span class="ruby-keyword">then</span> <span class="ruby-identifier">locale</span>.<span class="ruby-identifier">t</span> <span class="ruby-value">:about_x_hours</span>,  <span class="ruby-value">:count</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-number">1</span>
      <span class="ruby-comment"># 90 mins up to 24 hours</span>
      <span class="ruby-keyword">when</span> <span class="ruby-number">90</span><span class="ruby-operator">...</span><span class="ruby-number">1440</span>        <span class="ruby-keyword">then</span> <span class="ruby-identifier">locale</span>.<span class="ruby-identifier">t</span> <span class="ruby-value">:about_x_hours</span>,  <span class="ruby-value">:count</span> =<span class="ruby-operator">&gt;</span> (<span class="ruby-identifier">distance_in_minutes</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-number">60.0</span>).<span class="ruby-identifier">round</span>
      <span class="ruby-comment"># 24 hours up to 42 hours</span>
      <span class="ruby-keyword">when</span> <span class="ruby-number">1440</span><span class="ruby-operator">...</span><span class="ruby-number">2520</span>      <span class="ruby-keyword">then</span> <span class="ruby-identifier">locale</span>.<span class="ruby-identifier">t</span> <span class="ruby-value">:x_days</span>,         <span class="ruby-value">:count</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-number">1</span>
      <span class="ruby-comment"># 42 hours up to 30 days</span>
      <span class="ruby-keyword">when</span> <span class="ruby-number">2520</span><span class="ruby-operator">...</span><span class="ruby-number">43200</span>     <span class="ruby-keyword">then</span> <span class="ruby-identifier">locale</span>.<span class="ruby-identifier">t</span> <span class="ruby-value">:x_days</span>,         <span class="ruby-value">:count</span> =<span class="ruby-operator">&gt;</span> (<span class="ruby-identifier">distance_in_minutes</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-number">1440.0</span>).<span class="ruby-identifier">round</span>
      <span class="ruby-comment"># 30 days up to 60 days</span>
      <span class="ruby-keyword">when</span> <span class="ruby-number">43200</span><span class="ruby-operator">...</span><span class="ruby-number">86400</span>    <span class="ruby-keyword">then</span> <span class="ruby-identifier">locale</span>.<span class="ruby-identifier">t</span> <span class="ruby-value">:about_x_months</span>, <span class="ruby-value">:count</span> =<span class="ruby-operator">&gt;</span> (<span class="ruby-identifier">distance_in_minutes</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-number">43200.0</span>).<span class="ruby-identifier">round</span>
      <span class="ruby-comment"># 60 days up to 365 days</span>
      <span class="ruby-keyword">when</span> <span class="ruby-number">86400</span><span class="ruby-operator">...</span><span class="ruby-number">525600</span>   <span class="ruby-keyword">then</span> <span class="ruby-identifier">locale</span>.<span class="ruby-identifier">t</span> <span class="ruby-value">:x_months</span>,       <span class="ruby-value">:count</span> =<span class="ruby-operator">&gt;</span> (<span class="ruby-identifier">distance_in_minutes</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-number">43200.0</span>).<span class="ruby-identifier">round</span>
      <span class="ruby-keyword">else</span>
        <span class="ruby-keyword">if</span> <span class="ruby-identifier">from_time</span>.<span class="ruby-identifier">acts_like?</span>(<span class="ruby-value">:time</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">to_time</span>.<span class="ruby-identifier">acts_like?</span>(<span class="ruby-value">:time</span>)
          <span class="ruby-identifier">fyear</span> = <span class="ruby-identifier">from_time</span>.<span class="ruby-identifier">year</span>
          <span class="ruby-identifier">fyear</span> <span class="ruby-operator">+=</span> <span class="ruby-number">1</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">from_time</span>.<span class="ruby-identifier">month</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-number">3</span>
          <span class="ruby-identifier">tyear</span> = <span class="ruby-identifier">to_time</span>.<span class="ruby-identifier">year</span>
          <span class="ruby-identifier">tyear</span> <span class="ruby-operator">-=</span> <span class="ruby-number">1</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">to_time</span>.<span class="ruby-identifier">month</span> <span class="ruby-operator">&lt;</span> <span class="ruby-number">3</span>
          <span class="ruby-identifier">leap_years</span> = (<span class="ruby-identifier">fyear</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">tyear</span>) <span class="ruby-operator">?</span> <span class="ruby-number">0</span> <span class="ruby-operator">:</span> (<span class="ruby-identifier">fyear</span><span class="ruby-operator">..</span><span class="ruby-identifier">tyear</span>).<span class="ruby-identifier">count</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-constant">Date</span>.<span class="ruby-identifier">leap?</span>(<span class="ruby-identifier">x</span>)}
          <span class="ruby-identifier">minute_offset_for_leap_year</span> = <span class="ruby-identifier">leap_years</span> * <span class="ruby-number">1440</span>
          <span class="ruby-comment"># Discount the leap year days when calculating year distance.</span>
          <span class="ruby-comment"># e.g. if there are 20 leap year days between 2 dates having the same day</span>
          <span class="ruby-comment"># and month then the based on 365 days calculation</span>
          <span class="ruby-comment"># the distance in years will come out to over 80 years when in written</span>
          <span class="ruby-comment"># english it would read better as about 80 years.</span>
          <span class="ruby-identifier">minutes_with_offset</span> = <span class="ruby-identifier">distance_in_minutes</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">minute_offset_for_leap_year</span>
        <span class="ruby-keyword">else</span>
          <span class="ruby-identifier">minutes_with_offset</span> = <span class="ruby-identifier">distance_in_minutes</span>
        <span class="ruby-keyword">end</span>
        <span class="ruby-identifier">remainder</span>                   = (<span class="ruby-identifier">minutes_with_offset</span> <span class="ruby-operator">%</span> <span class="ruby-number">525600</span>)
        <span class="ruby-identifier">distance_in_years</span>           = (<span class="ruby-identifier">minutes_with_offset</span>.<span class="ruby-identifier">div</span> <span class="ruby-number">525600</span>)
        <span class="ruby-keyword">if</span> <span class="ruby-identifier">remainder</span> <span class="ruby-operator">&lt;</span> <span class="ruby-number">131400</span>
          <span class="ruby-identifier">locale</span>.<span class="ruby-identifier">t</span>(<span class="ruby-value">:about_x_years</span>,  <span class="ruby-value">:count</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">distance_in_years</span>)
        <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">remainder</span> <span class="ruby-operator">&lt;</span> <span class="ruby-number">394200</span>
          <span class="ruby-identifier">locale</span>.<span class="ruby-identifier">t</span>(<span class="ruby-value">:over_x_years</span>,   <span class="ruby-value">:count</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">distance_in_years</span>)
        <span class="ruby-keyword">else</span>
          <span class="ruby-identifier">locale</span>.<span class="ruby-identifier">t</span>(<span class="ruby-value">:almost_x_years</span>, <span class="ruby-value">:count</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">distance_in_years</span> <span class="ruby-operator">+</span> <span class="ruby-number">1</span>)
        <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-distance_of_time_in_words_to_now">
            
              <b>distance_of_time_in_words_to_now</b>(from_time, include_seconds_or_options = {})
            
            <a href="DateHelper.html#method-i-distance_of_time_in_words_to_now" name="method-i-distance_of_time_in_words_to_now" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-select_date">
            
              <b>select_date</b>(date = Date.current, options = {}, html_options = {})
            
            <a href="DateHelper.html#method-i-select_date" name="method-i-select_date" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a set of html select-tags (one for year, month, and day)
pre-selected with the <code>date</code>. It’s possible to explicitly set
the order of the tags using the <code>:order</code> option with an array of
symbols <code>:year</code>, <code>:month</code> and <code>:day</code> in
the desired order. If the array passed to the <code>:order</code> option
does not contain all the three symbols, all tags will be hidden.</p>

<p>If anything is passed in the html_options hash it will be applied to every
select tag in the set.</p>

<pre>my_date = Time.now + 6.days

# Generates a date select that defaults to the date in my_date (six days after today).
select_date(my_date)

# Generates a date select that defaults to today (no specified date).
select_date()

# Generates a date select that defaults to the date in my_date (six days after today)
# with the fields ordered year, month, day rather than month, day, year.
select_date(my_date, order: [:year, :month, :day])

# Generates a date select that discards the type of the field and defaults to the date in
# my_date (six days after today).
select_date(my_date, discard_type: true)

# Generates a date select that defaults to the date in my_date,
# which has fields separated by '/'.
select_date(my_date, date_separator: '/')

# Generates a date select that defaults to the datetime in my_date (six days after today)
# prefixed with 'payday' rather than 'date'.
select_date(my_date, prefix: 'payday')

# Generates a date select with a custom prompt. Use &lt;tt&gt;prompt: true&lt;/tt&gt; for generic prompts.
select_date(my_date, prompt: {day: 'Choose day', month: 'Choose month', year: 'Choose year'})
select_date(my_date, prompt: {hour: true}) # generic prompt for hours
select_date(my_date, prompt: true) # generic prompts for all</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-select_date_source')" id="l_method-i-select_date_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c52c2682bf03192755ccf8c15ab641090815cacf/actionpack/lib/action_view/helpers/date_helper.rb#L414" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-select_date_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/date_helper.rb, line 414</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">select_date</span>(<span class="ruby-identifier">date</span> = <span class="ruby-constant">Date</span>.<span class="ruby-identifier">current</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
  <span class="ruby-constant">DateTimeSelector</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">date</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">html_options</span>).<span class="ruby-identifier">select_date</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-select_datetime">
            
              <b>select_datetime</b>(datetime = Time.current, options = {}, html_options = {})
            
            <a href="DateHelper.html#method-i-select_datetime" name="method-i-select_datetime" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a set of html select-tags (one for year, month, day, hour, minute,
and second) pre-selected with the <code>datetime</code>. It’s also possible
to explicitly set the order of the tags using the <code>:order</code>
option with an array of symbols <code>:year</code>, <code>:month</code> and
<code>:day</code> in the desired order. If you do not supply a <a
href="../../Symbol.html">Symbol</a>, it will be appended onto the
<code>:order</code> passed in. You can also add
<code>:date_separator</code>, <code>:datetime_separator</code> and
<code>:time_separator</code> keys to the <code>options</code> to control
visual display of the elements.</p>

<p>If anything is passed in the html_options hash it will be applied to every
select tag in the set.</p>

<pre>my_date_time = Time.now + 4.days

# Generates a datetime select that defaults to the datetime in my_date_time (four days after today).
select_datetime(my_date_time)

# Generates a datetime select that defaults to today (no specified datetime)
select_datetime()

# Generates a datetime select that defaults to the datetime in my_date_time (four days after today)
# with the fields ordered year, month, day rather than month, day, year.
select_datetime(my_date_time, order: [:year, :month, :day])

# Generates a datetime select that defaults to the datetime in my_date_time (four days after today)
# with a '/' between each date field.
select_datetime(my_date_time, date_separator: '/')

# Generates a datetime select that defaults to the datetime in my_date_time (four days after today)
# with a date fields separated by '/', time fields separated by '' and the date and time fields
# separated by a comma (',').
select_datetime(my_date_time, date_separator: '/', time_separator: '', datetime_separator: ',')

# Generates a datetime select that discards the type of the field and defaults to the datetime in
# my_date_time (four days after today)
select_datetime(my_date_time, discard_type: true)

# Generate a datetime field with hours in the AM/PM format
select_datetime(my_date_time, ampm: true)

# Generates a datetime select that defaults to the datetime in my_date_time (four days after today)
# prefixed with 'payday' rather than 'date'
select_datetime(my_date_time, prefix: 'payday')

# Generates a datetime select with a custom prompt. Use &lt;tt&gt;prompt: true&lt;/tt&gt; for generic prompts.
select_datetime(my_date_time, prompt: {day: 'Choose day', month: 'Choose month', year: 'Choose year'})
select_datetime(my_date_time, prompt: {hour: true}) # generic prompt for hours
select_datetime(my_date_time, prompt: true) # generic prompts for all</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-select_datetime_source')" id="l_method-i-select_datetime_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c52c2682bf03192755ccf8c15ab641090815cacf/actionpack/lib/action_view/helpers/date_helper.rb#L375" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-select_datetime_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/date_helper.rb, line 375</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">select_datetime</span>(<span class="ruby-identifier">datetime</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">current</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
  <span class="ruby-constant">DateTimeSelector</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">datetime</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">html_options</span>).<span class="ruby-identifier">select_datetime</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-select_day">
            
              <b>select_day</b>(date, options = {}, html_options = {})
            
            <a href="DateHelper.html#method-i-select_day" name="method-i-select_day" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a select tag with options for each of the days 1 through 31 with
the current day selected. The <code>date</code> can also be substituted for
a day number. If you want to display days with a leading zero set the
<code>:use_two_digit_numbers</code> key in <code>options</code> to true.
Override the field name using the <code>:field_name</code> option, ‘day’ by
default.</p>

<pre>my_date = Time.now + 2.days

# Generates a select field for days that defaults to the day for the date in my_date.
select_day(my_time)

# Generates a select field for days that defaults to the number given.
select_day(5)

# Generates a select field for days that defaults to the number given, but displays it with two digits.
select_day(5, use_two_digit_numbers: true)

# Generates a select field for days that defaults to the day for the date in my_date
# that is named 'due' rather than 'day'.
select_day(my_time, field_name: 'due')

# Generates a select field for days with a custom prompt. Use &lt;tt&gt;prompt: true&lt;/tt&gt; for a
# generic prompt.
select_day(5, prompt: 'Choose day')</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-select_day_source')" id="l_method-i-select_day_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c52c2682bf03192755ccf8c15ab641090815cacf/actionpack/lib/action_view/helpers/date_helper.rb#L557" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-select_day_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/date_helper.rb, line 557</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">select_day</span>(<span class="ruby-identifier">date</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
  <span class="ruby-constant">DateTimeSelector</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">date</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">html_options</span>).<span class="ruby-identifier">select_day</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-select_hour">
            
              <b>select_hour</b>(datetime, options = {}, html_options = {})
            
            <a href="DateHelper.html#method-i-select_hour" name="method-i-select_hour" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a select tag with options for each of the hours 0 through 23 with
the current hour selected. The <code>datetime</code> can be either a
<code>Time</code> or <code>DateTime</code> object or an integer. Override
the field name using the <code>:field_name</code> option, ‘hour’ by
default.</p>

<pre>my_time = Time.now + 6.hours

# Generates a select field for hours that defaults to the hour for the time in my_time.
select_hour(my_time)

# Generates a select field for hours that defaults to the number given.
select_hour(13)

# Generates a select field for hours that defaults to the hour for the time in my_time
# that is named 'stride' rather than 'hour'.
select_hour(my_time, field_name: 'stride')

# Generates a select field for hours with a custom prompt. Use &lt;tt&gt;prompt: true&lt;/tt&gt; for a
# generic prompt.
select_hour(13, prompt: 'Choose hour')

# Generate a select field for hours in the AM/PM format
select_hour(my_time, ampm: true)

# Generates a select field that includes options for hours from 2 to 14.
select_hour(my_time, start_hour: 2, end_hour: 14)</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-select_hour_source')" id="l_method-i-select_hour_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c52c2682bf03192755ccf8c15ab641090815cacf/actionpack/lib/action_view/helpers/date_helper.rb#L530" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-select_hour_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/date_helper.rb, line 530</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">select_hour</span>(<span class="ruby-identifier">datetime</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
  <span class="ruby-constant">DateTimeSelector</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">datetime</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">html_options</span>).<span class="ruby-identifier">select_hour</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-select_minute">
            
              <b>select_minute</b>(datetime, options = {}, html_options = {})
            
            <a href="DateHelper.html#method-i-select_minute" name="method-i-select_minute" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a select tag with options for each of the minutes 0 through 59 with
the current minute selected. Also can return a select tag with options by
<code>minute_step</code> from 0 through 59 with the 00 minute selected. The
<code>datetime</code> can be either a <code>Time</code> or
<code>DateTime</code> object or an integer. Override the field name using
the <code>:field_name</code> option, ‘minute’ by default.</p>

<pre>my_time = Time.now + 6.hours

# Generates a select field for minutes that defaults to the minutes for the time in my_time.
select_minute(my_time)

# Generates a select field for minutes that defaults to the number given.
select_minute(14)

# Generates a select field for minutes that defaults to the minutes for the time in my_time
# that is named 'moment' rather than 'minute'.
select_minute(my_time, field_name: 'moment')

# Generates a select field for minutes with a custom prompt. Use &lt;tt&gt;prompt: true&lt;/tt&gt; for a
# generic prompt.
select_minute(14, prompt: 'Choose minutes')</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-select_minute_source')" id="l_method-i-select_minute_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c52c2682bf03192755ccf8c15ab641090815cacf/actionpack/lib/action_view/helpers/date_helper.rb#L501" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-select_minute_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/date_helper.rb, line 501</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">select_minute</span>(<span class="ruby-identifier">datetime</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
  <span class="ruby-constant">DateTimeSelector</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">datetime</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">html_options</span>).<span class="ruby-identifier">select_minute</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-select_month">
            
              <b>select_month</b>(date, options = {}, html_options = {})
            
            <a href="DateHelper.html#method-i-select_month" name="method-i-select_month" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a select tag with options for each of the months January through
December with the current month selected. The month names are presented as
keys (what’s shown to the user) and the month numbers (1-12) are used as
values (what’s submitted to the server). It’s also possible to use month
numbers for the presentation instead of names – set the
<code>:use_month_numbers</code> key in <code>options</code> to true for
this to happen. If you want both numbers and names, set the
<code>:add_month_numbers</code> key in <code>options</code> to true. If you
would prefer to show month names as abbreviations, set the
<code>:use_short_month</code> key in <code>options</code> to true. If you
want to use your own month names, set the <code>:use_month_names</code> key
in <code>options</code> to an array of 12 month names. If you want to
display months with a leading zero set the
<code>:use_two_digit_numbers</code> key in <code>options</code> to true.
Override the field name using the <code>:field_name</code> option, ‘month’
by default.</p>

<pre># Generates a select field for months that defaults to the current month that
# will use keys like &quot;January&quot;, &quot;March&quot;.
select_month(Date.today)

# Generates a select field for months that defaults to the current month that
# is named &quot;start&quot; rather than &quot;month&quot;.
select_month(Date.today, field_name: 'start')

# Generates a select field for months that defaults to the current month that
# will use keys like &quot;1&quot;, &quot;3&quot;.
select_month(Date.today, use_month_numbers: true)

# Generates a select field for months that defaults to the current month that
# will use keys like &quot;1 - January&quot;, &quot;3 - March&quot;.
select_month(Date.today, add_month_numbers: true)

# Generates a select field for months that defaults to the current month that
# will use keys like &quot;Jan&quot;, &quot;Mar&quot;.
select_month(Date.today, use_short_month: true)

# Generates a select field for months that defaults to the current month that
# will use keys like &quot;Januar&quot;, &quot;Marts.&quot;
select_month(Date.today, use_month_names: %w(Januar Februar Marts ...))

# Generates a select field for months that defaults to the current month that
# will use keys with two digit numbers like &quot;01&quot;, &quot;03&quot;.
select_month(Date.today, use_two_digit_numbers: true)

# Generates a select field for months with a custom prompt. Use &lt;tt&gt;prompt: true&lt;/tt&gt; for a
# generic prompt.
select_month(14, prompt: 'Choose month')</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-select_month_source')" id="l_method-i-select_month_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c52c2682bf03192755ccf8c15ab641090815cacf/actionpack/lib/action_view/helpers/date_helper.rb#L602" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-select_month_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/date_helper.rb, line 602</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">select_month</span>(<span class="ruby-identifier">date</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
  <span class="ruby-constant">DateTimeSelector</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">date</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">html_options</span>).<span class="ruby-identifier">select_month</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-select_second">
            
              <b>select_second</b>(datetime, options = {}, html_options = {})
            
            <a href="DateHelper.html#method-i-select_second" name="method-i-select_second" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a select tag with options for each of the seconds 0 through 59 with
the current second selected. The <code>datetime</code> can be either a
<code>Time</code> or <code>DateTime</code> object or an integer. Override
the field name using the <code>:field_name</code> option, ‘second’ by
default.</p>

<pre>my_time = Time.now + 16.minutes

# Generates a select field for seconds that defaults to the seconds for the time in my_time.
select_second(my_time)

# Generates a select field for seconds that defaults to the number given.
select_second(33)

# Generates a select field for seconds that defaults to the seconds for the time in my_time
# that is named 'interval' rather than 'second'.
select_second(my_time, field_name: 'interval')

# Generates a select field for seconds with a custom prompt. Use &lt;tt&gt;prompt: true&lt;/tt&gt; for a
# generic prompt.
select_second(14, prompt: 'Choose seconds')</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-select_second_source')" id="l_method-i-select_second_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c52c2682bf03192755ccf8c15ab641090815cacf/actionpack/lib/action_view/helpers/date_helper.rb#L477" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-select_second_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/date_helper.rb, line 477</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">select_second</span>(<span class="ruby-identifier">datetime</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
  <span class="ruby-constant">DateTimeSelector</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">datetime</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">html_options</span>).<span class="ruby-identifier">select_second</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-select_time">
            
              <b>select_time</b>(datetime = Time.current, options = {}, html_options = {})
            
            <a href="DateHelper.html#method-i-select_time" name="method-i-select_time" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a set of html select-tags (one for hour and minute). You can set
<code>:time_separator</code> key to format the output, and the
<code>:include_seconds</code> option to include an input for seconds.</p>

<p>If anything is passed in the html_options hash it will be applied to every
select tag in the set.</p>

<pre>my_time = Time.now + 5.days + 7.hours + 3.minutes + 14.seconds

# Generates a time select that defaults to the time in my_time.
select_time(my_time)

# Generates a time select that defaults to the current time (no specified time).
select_time()

# Generates a time select that defaults to the time in my_time,
# which has fields separated by ':'.
select_time(my_time, time_separator: ':')

# Generates a time select that defaults to the time in my_time,
# that also includes an input for seconds.
select_time(my_time, include_seconds: true)

# Generates a time select that defaults to the time in my_time, that has fields
# separated by ':' and includes an input for seconds.
select_time(my_time, time_separator: ':', include_seconds: true)

# Generate a time select field with hours in the AM/PM format
select_time(my_time, ampm: true)

# Generates a time select field with hours that range from 2 to 14
select_time(my_time, start_hour: 2, end_hour: 14)

# Generates a time select with a custom prompt. Use &lt;tt&gt;:prompt&lt;/tt&gt; to true for generic prompts.
select_time(my_time, prompt: {day: 'Choose day', month: 'Choose month', year: 'Choose year'})
select_time(my_time, prompt: {hour: true}) # generic prompt for hours
select_time(my_time, prompt: true) # generic prompts for all</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-select_time_source')" id="l_method-i-select_time_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c52c2682bf03192755ccf8c15ab641090815cacf/actionpack/lib/action_view/helpers/date_helper.rb#L454" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-select_time_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/date_helper.rb, line 454</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">select_time</span>(<span class="ruby-identifier">datetime</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">current</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
  <span class="ruby-constant">DateTimeSelector</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">datetime</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">html_options</span>).<span class="ruby-identifier">select_time</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-select_year">
            
              <b>select_year</b>(date, options = {}, html_options = {})
            
            <a href="DateHelper.html#method-i-select_year" name="method-i-select_year" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a select tag with options for each of the five years on each side
of the current, which is selected. The five year radius can be changed
using the <code>:start_year</code> and <code>:end_year</code> keys in the
<code>options</code>. Both ascending and descending year lists are
supported by making <code>:start_year</code> less than or greater than
<code>:end_year</code>. The <code>date</code> can also be substituted for a
year given as a number. Override the field name using the
<code>:field_name</code> option, ‘year’ by default.</p>

<pre># Generates a select field for years that defaults to the current year that
# has ascending year values.
select_year(Date.today, start_year: 1992, end_year: 2007)

# Generates a select field for years that defaults to the current year that
# is named 'birth' rather than 'year'.
select_year(Date.today, field_name: 'birth')

# Generates a select field for years that defaults to the current year that
# has descending year values.
select_year(Date.today, start_year: 2005, end_year: 1900)

# Generates a select field for years that defaults to the year 2006 that
# has ascending year values.
select_year(2006, start_year: 2000, end_year: 2010)

# Generates a select field for years with a custom prompt. Use &lt;tt&gt;prompt: true&lt;/tt&gt; for a
# generic prompt.
select_year(14, prompt: 'Choose year')</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-select_year_source')" id="l_method-i-select_year_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c52c2682bf03192755ccf8c15ab641090815cacf/actionpack/lib/action_view/helpers/date_helper.rb#L631" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-select_year_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/date_helper.rb, line 631</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">select_year</span>(<span class="ruby-identifier">date</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
  <span class="ruby-constant">DateTimeSelector</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">date</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">html_options</span>).<span class="ruby-identifier">select_year</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-time_ago_in_words">
            
              <b>time_ago_in_words</b>(from_time, include_seconds_or_options = {})
            
            <a href="DateHelper.html#method-i-time_ago_in_words" name="method-i-time_ago_in_words" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Like <code>distance_of_time_in_words</code>, but where <code>to_time</code>
is fixed to <code>Time.now</code>.</p>

<pre class="ruby"><span class="ruby-identifier">time_ago_in_words</span>(<span class="ruby-value">3</span>.<span class="ruby-identifier">minutes</span>.<span class="ruby-identifier">from_now</span>)                 <span class="ruby-comment"># =&gt; 3 minutes</span>
<span class="ruby-identifier">time_ago_in_words</span>(<span class="ruby-value">3</span>.<span class="ruby-identifier">minutes</span>.<span class="ruby-identifier">ago</span>)                      <span class="ruby-comment"># =&gt; 3 minutes</span>
<span class="ruby-identifier">time_ago_in_words</span>(<span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span> <span class="ruby-operator">-</span> <span class="ruby-value">15</span>.<span class="ruby-identifier">hours</span>)                <span class="ruby-comment"># =&gt; about 15 hours</span>
<span class="ruby-identifier">time_ago_in_words</span>(<span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>)                           <span class="ruby-comment"># =&gt; less than a minute</span>
<span class="ruby-identifier">time_ago_in_words</span>(<span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>, <span class="ruby-identifier">include_seconds</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>) <span class="ruby-comment"># =&gt; less than 5 seconds</span>

<span class="ruby-identifier">from_time</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span> <span class="ruby-operator">-</span> <span class="ruby-value">3</span>.<span class="ruby-identifier">days</span> <span class="ruby-operator">-</span> <span class="ruby-value">14</span>.<span class="ruby-identifier">minutes</span> <span class="ruby-operator">-</span> <span class="ruby-value">25</span>.<span class="ruby-identifier">seconds</span>
<span class="ruby-identifier">time_ago_in_words</span>(<span class="ruby-identifier">from_time</span>)      <span class="ruby-comment"># =&gt; 3 days</span>

<span class="ruby-identifier">from_time</span> = (<span class="ruby-value">3</span>.<span class="ruby-identifier">days</span> <span class="ruby-operator">+</span> <span class="ruby-value">14</span>.<span class="ruby-identifier">minutes</span> <span class="ruby-operator">+</span> <span class="ruby-value">25</span>.<span class="ruby-identifier">seconds</span>).<span class="ruby-identifier">ago</span>
<span class="ruby-identifier">time_ago_in_words</span>(<span class="ruby-identifier">from_time</span>)      <span class="ruby-comment"># =&gt; 3 days</span>
</pre>

<p>Note that you cannot pass a <code>Numeric</code> value to
<code>time_ago_in_words</code>.</p>
            </div>
          
          
          
            <div class="aka">
              Also aliased as: <a href="DateHelper.html#method-i-distance_of_time_in_words_to_now">distance_of_time_in_words_to_now</a>
            </div>
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-time_ago_in_words_source')" id="l_method-i-time_ago_in_words_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c52c2682bf03192755ccf8c15ab641090815cacf/actionpack/lib/action_view/helpers/date_helper.rb#L160" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-time_ago_in_words_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/date_helper.rb, line 160</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">time_ago_in_words</span>(<span class="ruby-identifier">from_time</span>, <span class="ruby-identifier">include_seconds_or_options</span> = {})
  <span class="ruby-identifier">distance_of_time_in_words</span>(<span class="ruby-identifier">from_time</span>, <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>, <span class="ruby-identifier">include_seconds_or_options</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-time_select">
            
              <b>time_select</b>(object_name, method, options = {}, html_options = {})
            
            <a href="DateHelper.html#method-i-time_select" name="method-i-time_select" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a set of select tags (one for hour, minute and optionally second)
pre-selected for accessing a specified time-based attribute (identified by
<code>method</code>) on an object assigned to the template (identified by
<code>object</code>). You can include the seconds with
<code>:include_seconds</code>. You can get hours in the AM/PM format with
<code>:ampm</code> option.</p>

<p>This method will also generate 3 input hidden tags, for the actual year,
month and day unless the option <code>:ignore_date</code> is set to
<code>true</code>. If you set the <code>:ignore_date</code> to
<code>true</code>, you must have a <code>date_select</code> on the same
method within the form otherwise an exception will be raised.</p>

<p>If anything is passed in the html_options hash it will be applied to every
select tag in the set.</p>

<pre># Creates a time select tag that, when POSTed, will be stored in the article variable in the sunrise attribute.
time_select(&quot;article&quot;, &quot;sunrise&quot;)

# Creates a time select tag with a seconds field that, when POSTed, will be stored in the article variables in
# the sunrise attribute.
time_select(&quot;article&quot;, &quot;start_time&quot;, include_seconds: true)

# You can set the &lt;tt&gt;:minute_step&lt;/tt&gt; to 15 which will give you: 00, 15, 30 and 45.
time_select 'game', 'game_time', {minute_step: 15}

# Creates a time select tag with a custom prompt. Use &lt;tt&gt;prompt: true&lt;/tt&gt; for generic prompts.
time_select(&quot;article&quot;, &quot;written_on&quot;, prompt: {hour: 'Choose hour', minute: 'Choose minute', second: 'Choose seconds'})
time_select(&quot;article&quot;, &quot;written_on&quot;, prompt: {hour: true}) # generic prompt for hours
time_select(&quot;article&quot;, &quot;written_on&quot;, prompt: true) # generic prompts for all

# You can set :ampm option to true which will show the hours as: 12 PM, 01 AM .. 11 PM.
time_select 'game', 'game_time', {ampm: true}</pre>

<p>The selects are prepared for multi-parameter assignment to an Active Record
object.</p>

<p>Note: If the day is not included as an option but the month is, the day
will be set to the 1st to ensure that all month choices are valid.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-time_select_source')" id="l_method-i-time_select_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c52c2682bf03192755ccf8c15ab641090815cacf/actionpack/lib/action_view/helpers/date_helper.rb#L291" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-time_select_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/date_helper.rb, line 291</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">time_select</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
  <span class="ruby-constant">Tags</span><span class="ruby-operator">::</span><span class="ruby-constant">TimeSelect</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-keyword">self</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">html_options</span>).<span class="ruby-identifier">render</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-time_tag">
            
              <b>time_tag</b>(date_or_time, *args, &amp;block)
            
            <a href="DateHelper.html#method-i-time_tag" name="method-i-time_tag" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns an html time tag for the given date or time.</p>

<pre>time_tag Date.today  # =&gt;
  &lt;time datetime=&quot;2010-11-04&quot;&gt;November 04, 2010&lt;/time&gt;
time_tag Time.now  # =&gt;
  &lt;time datetime=&quot;2010-11-04T17:55:45+01:00&quot;&gt;November 04, 2010 17:55&lt;/time&gt;
time_tag Date.yesterday, 'Yesterday'  # =&gt;
  &lt;time datetime=&quot;2010-11-03&quot;&gt;Yesterday&lt;/time&gt;
time_tag Date.today, pubdate: true  # =&gt;
  &lt;time datetime=&quot;2010-11-04&quot; pubdate=&quot;pubdate&quot;&gt;November 04, 2010&lt;/time&gt;
time_tag Date.today, datetime: Date.today.strftime('%G-W%V') # =&gt;
  &lt;time datetime=&quot;2010-W44&quot;&gt;November 04, 2010&lt;/time&gt;

&lt;%= time_tag Time.now do %&gt;
  &lt;span&gt;Right now&lt;/span&gt;
&lt;% end %&gt;
# =&gt; &lt;time datetime=&quot;2010-11-04T17:55:45+01:00&quot;&gt;&lt;span&gt;Right now&lt;/span&gt;&lt;/time&gt;</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-time_tag_source')" id="l_method-i-time_tag_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c52c2682bf03192755ccf8c15ab641090815cacf/actionpack/lib/action_view/helpers/date_helper.rb#L652" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-time_tag_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/date_helper.rb, line 652</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">time_tag</span>(<span class="ruby-identifier">date_or_time</span>, *<span class="ruby-identifier">args</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-identifier">options</span>  = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">extract_options!</span>
  <span class="ruby-identifier">format</span>   = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:format</span>) <span class="ruby-operator">||</span> <span class="ruby-value">:long</span>
  <span class="ruby-identifier">content</span>  = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">||</span> <span class="ruby-constant">I18n</span>.<span class="ruby-identifier">l</span>(<span class="ruby-identifier">date_or_time</span>, <span class="ruby-value">:format</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">format</span>)
  <span class="ruby-identifier">datetime</span> = <span class="ruby-identifier">date_or_time</span>.<span class="ruby-identifier">acts_like?</span>(<span class="ruby-value">:time</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">date_or_time</span>.<span class="ruby-identifier">xmlschema</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">date_or_time</span>.<span class="ruby-identifier">iso8601</span>

  <span class="ruby-identifier">content_tag</span>(<span class="ruby-value">:time</span>, <span class="ruby-identifier">content</span>, <span class="ruby-identifier">options</span>.<span class="ruby-identifier">reverse_merge</span>(<span class="ruby-value">:datetime</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">datetime</span>), &amp;<span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    